﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NHibernate;
using DotNet.Common.NHibernateUtil;
using ZLCMS.Data.Model;

namespace ZLCMS.Web.SystemManage.Basics.FormInfo
{
    public partial class FormObjectDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["object_id"] = Int32.Parse(Request["objectid"]);

                using(ISession session = SessionFactoryHelper.CreateSession())
                {

                    SysFormObjectDef formObject = session.Get<SysFormObjectDef>(ViewState["object_id"]);
                    status.SelectedValue = formObject.ObjectStatus;

                    repeater1.DataSource = session.CreateQuery("from SysFormObjectField where ObjectId=" + ViewState["object_id"] ).List<SysFormObjectField>();

                }
                repeater1.DataBind();
            }
            else
            {
                using (ISession session = SessionFactoryHelper.CreateSession())
                {

                    SysFormObjectDef formObject = session.Get<SysFormObjectDef>(ViewState["object_id"]);
                    formObject.ObjectStatus = status.SelectedValue;
                    session.Update(formObject);

                    session.Flush();
                }

                //框架返回成功提示
                ZLCMS.Business.DwzFrame.FrameHelper _framePage = new ZLCMS.Business.DwzFrame.FrameHelper(this);
                ZLCMS.Business.DwzFrame.ReturnCode rc = new ZLCMS.Business.DwzFrame.ReturnCode()
                {
                    statusCode = 200,
                    message = "操作成功"
                };

                rc.callbackType = "forward";
                rc.forwardUrl = "/SystemManage/Basics/FormInfo/FormObjectDetail.aspx?tabid=FormObjectDetail&objectid=" + ViewState["object_id"];



                _framePage.Alert(rc);
            }
        }
    }
}